package cn.seaboot.admin.other.service;

import cn.seaboot.admin.other.bean.Bulletin;
import cn.seaboot.admin.other.dao.BulletinDao;
import cn.seaboot.commons.core.UUIDUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 系统公告
 *
 * @author Mr.css on 2018-6-20
 */
@Service
public class BulletinService {

    @Resource
    private BulletinDao bulletinDao;

    /**
     * 新增
     *
     * @param bulletin pojo
     * @return affected rows
     */
    public int insert(Bulletin bulletin) {
        bulletin.setId(UUIDUtils.genUUID32());
        return bulletinDao.insert(bulletin);
    }

    /**
     * 新增
     *
     * @param content 内容
     * @return affected rows
     */
    public int insertNotice(String content) {
        Bulletin editor = new Bulletin();
        editor.setContent(content);
        int noticeType = 1;
        editor.setBulletinType(noticeType);
        return insert(editor);
    }

    /**
     * 列表查询
     *
     * @param params 参数
     * @return list
     */
    public List<Bulletin> queryList(Map<String, Object> params) {
        return bulletinDao.selectList(params);
    }

    /**
     * 按ID删除
     *
     * @param id ID
     * @return affected rows
     */
    public int deleteById(String id) {
        return bulletinDao.deleteById(id);
    }

    /**
     * 按ID修改
     *
     * @param id      ID
     * @param content 内容
     * @return affected rows
     */
    public int updateById(String id, String content) {
        Bulletin sysUserExcel = new Bulletin();
        sysUserExcel.setId(id);
        sysUserExcel.setContent(content);
        return bulletinDao.updateById(sysUserExcel);
    }

    /**
     * 查
     *
     * @param id id
     * @return pojo
     */
    public Bulletin queryById(String id) {
        return bulletinDao.selectById(id);
    }

    /**
     * 按照类型查询
     *
     * @param bulletinType 类型
     * @return pojo
     */
    public Bulletin selectLastByType(int bulletinType) {
        return bulletinDao.selectLastByType(bulletinType);
    }
}
